package com.zjsd.sqeybusiness.controller;

import java.text.ParseException;
import java.util.List;

import com.zjsd.sqeybusiness.dto.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.zjsd.sqeybusiness.domain.Busitask;
import com.zjsd.sqeybusiness.service.IBusitaskService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 业务员目标任务Controller
 *
 * @author Zheng
 * @date 2021-07-14
 */
@RestController
@RequestMapping("/sqeybusiness/busitask")
public class BusitaskController extends BaseController
{
    @Autowired
    private IBusitaskService busitaskService;

    /**
     * 查询业务员目标任务列表 @PreAuthorize("@ss.hasPermi('sqeybusiness:busitask:list')")
     */

    @GetMapping("/list")
    public TableDataInfo list(Busitask busitask)
    {
        // startPage();
        List<Busitask> list = busitaskService.selectBusitaskList(busitask);
        return getDataTable(list);
    }

    /**
     * 导出业务员目标任务列表
     */
    @PreAuthorize("@ss.hasPermi('sqeybusiness:busitask:export')")
    //@Log(title = "业务员目标任务", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Busitask busitask)
    {
        List<Busitask> list = busitaskService.selectBusitaskList(busitask);
        ExcelUtil<Busitask> util = new ExcelUtil<Busitask>(Busitask.class);
        return util.exportExcel(list, "busitask");
    }

    /**
     * 获取业务员目标任务详细信息
     */
    @PreAuthorize("@ss.hasPermi('sqeybusiness:busitask:query')")
    @GetMapping(value = "/{taskid}")
    public AjaxResult getInfo(@PathVariable("taskid") Long taskid)
    {
        return AjaxResult.success(busitaskService.selectBusitaskById(taskid));
    }

    /**
     * 新增业务员目标任务
    @PreAuthorize("@ss.hasPermi('sqeybusiness:busitask:add')")
     */
    //@Log(title = "业务员目标任务", businessType = BusinessType.INSERT)
    @PostMapping(value = "/addBusiTask")
    public AjaxResult add( Busitask busitask)
    {
        return toAjax(busitaskService.insertBusitask(busitask));
    }

    /**
     * 新增省区目标任务
     @PreAuthorize("@ss.hasPermi('sqeybusiness:busitask:add')")
     */
    //@Log(title = "业务员目标任务", businessType = BusinessType.INSERT)
    @PostMapping(value = "/addDeptTask")
    public AjaxResult addDeptTask(@RequestBody  DeptTaskDTO deptTaskDTO)
    {
        return toAjax(busitaskService.insertDeptTask(deptTaskDTO));
    }


    /**
     * 修改业务员目标任务 @PreAuthorize("@ss.hasPermi('sqeybusiness:busitask:edit')")
     */

    //@Log(title = "业务员目标任务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Busitask busitask)
    {
        return toAjax(busitaskService.updateBusitask(busitask));
    }

    /**
     * 删除业务员目标任务
     */
    @PreAuthorize("@ss.hasPermi('sqeybusiness:busitask:remove')")
    //@Log(title = "业务员目标任务", businessType = BusinessType.DELETE)
	@DeleteMapping("/{taskids}")
    public AjaxResult remove(@PathVariable Long[] taskids)
    {
        return toAjax(busitaskService.deleteBusitaskByIds(taskids));
    }

    /**
     * 查询登录人部门和岗位信息
     */
    //@Log(title = "查询登录人部门和岗位信息", businessType = BusinessType.INSERT)
    @PostMapping(value = "/queryUserInfo")
    public AjaxResult queryUserInfo(@RequestBody UserInfoDTO userInfoDTO)
    {
        UserInfoDTO userInfoDTO1 = busitaskService.queryUserInfo(userInfoDTO);
        return AjaxResult.success(userInfoDTO1);
    }

    /**
     * 查询登录人所属部门目标任务情况
     *
     */
    //@Log(title = "查询登录人所属部门目标任务情况", businessType = BusinessType.INSERT)
    @PostMapping(value = "/queryDeptBusiTask")
    public AjaxResult queryDeptBusiTask(@RequestBody TaskDTO taskDTO)
    {
        TaskDTO taskDTO1 = busitaskService.queryDeptBusiTask(taskDTO);
        return AjaxResult.success(taskDTO1);
    }




    // 查询首页今日业绩
    //@Log(title = "查询首页今日业绩", businessType = BusinessType.INSERT)
    @PostMapping(value = "/queryJryj")
    public AjaxResult queryJryj(JryjDTO jryjDTO)
    {
        JryjDTO jryjDTO1 = busitaskService.queryJryj(jryjDTO);
        return AjaxResult.success(jryjDTO1);
    }

    // 查询首页今日业绩
    //@Log(title = "查询首页今日业绩", businessType = BusinessType.INSERT)
    @PostMapping(value = "/queryJryjWeb")
    public AjaxResult queryJryjWeb(@RequestBody  JryjDTO jryjDTO)
    {
        JryjDTO jryjDTO1 = busitaskService.queryJryj(jryjDTO);
        return AjaxResult.success(jryjDTO1);
    }



    // 查询首页今日业绩
    //@Log(title = "查询业务员业绩", businessType = BusinessType.INSERT)
    @PostMapping(value = "/queryYwyAchievements")
    public AjaxResult queryYwyAchievements (YwyAchDTO ywyAchDTO) throws ParseException {
        YwyAchDTO ywyAchDTO1 = busitaskService.queryYwyAchievements(ywyAchDTO);
        return AjaxResult.success(ywyAchDTO1);
    }

    // 查询首页今日业绩
    //@Log(title = "查询业务员业绩", businessType = BusinessType.INSERT)
    @PostMapping(value = "/queryYwyAchievementsWeb")
    public AjaxResult queryYwyAchievementsWeb (@RequestBody  YwyAchDTO ywyAchDTO) throws ParseException {
        YwyAchDTO ywyAchDTO1 = busitaskService.queryYwyAchievements(ywyAchDTO);
        return AjaxResult.success(ywyAchDTO1);
    }


    //@Log(title = "查询业务员月排行", businessType = BusinessType.INSERT)
    @PostMapping(value = "/queryMonthRanking")
    public AjaxResult queryMonthRanking (YwyAchDTO ywyAchDTO) throws ParseException {
        YwyAchDTO ywyAchDTO1 = busitaskService.queryMonthRanking(ywyAchDTO);
        return AjaxResult.success(ywyAchDTO1);
    }

    //@Log(title = "查询业务员月排行", businessType = BusinessType.INSERT)
    @PostMapping(value = "/queryMonthRankingWeb")
    public AjaxResult queryMonthRankingWeb (@RequestBody  YwyAchDTO ywyAchDTO) throws ParseException {
        YwyAchDTO ywyAchDTO1 = busitaskService.queryMonthRanking(ywyAchDTO);
        return AjaxResult.success(ywyAchDTO1);
    }

    //@Log(title = "查询业务员周排行", businessType = BusinessType.INSERT)
    @PostMapping(value = "/queryWeekRanking")
    public AjaxResult queryWeekRanking (YwyAchDTO ywyAchDTO) throws ParseException {
        YwyAchDTO ywyAchDTO1 = busitaskService.queryWeekRanking(ywyAchDTO);
        return AjaxResult.success(ywyAchDTO1);
    }

    //@Log(title = "查询业务员周排行", businessType = BusinessType.INSERT)
    @PostMapping(value = "/queryYearRanking")
    public AjaxResult queryYearRanking (YwyAchDTO ywyAchDTO) throws ParseException {
        YwyAchDTO ywyAchDTO1 = busitaskService.queryYearRanking(ywyAchDTO);
        return AjaxResult.success(ywyAchDTO1);
    }


    //@Log(title = "查询当月情况", businessType = BusinessType.INSERT)
    @PostMapping(value = "/queryMonthStatics")
    public AjaxResult queryMonthStatics (MonthStaticsDTO monthStaticsDTO) throws ParseException {
        MonthStaticsDTO monthStaticsDTO1 = busitaskService.queryMonthStatics(monthStaticsDTO);
        return AjaxResult.success(monthStaticsDTO1);
    }

    //@Log(title = "web查询当月情况", businessType = BusinessType.INSERT)
    @PostMapping(value = "/queryMonthStaticsWeb")
    public AjaxResult queryMonthStaticsWeb (@RequestBody  MonthStaticsDTO monthStaticsDTO) throws ParseException {
        MonthStaticsDTO monthStaticsDTO1 = busitaskService.queryMonthStatics(monthStaticsDTO);
        return AjaxResult.success(monthStaticsDTO1);
    }


    //@Log(title = "查询任务填报情况", businessType = BusinessType.INSERT)
    @PostMapping(value = "/queryTaskStatics")
    public AjaxResult queryTaskStatics (TaskStaticsDTO taskStaticsDTO) throws ParseException {
        TaskStaticsDTO taskStaticsDTO1 = busitaskService.queryTaskStatics(taskStaticsDTO);
        return AjaxResult.success(taskStaticsDTO1);
    }

    /**
     * 查询月度进展情况详情

    @PreAuthorize("@ss.hasPermi('sqeybusiness:busitask:list')")*/
    @PostMapping("/queryDeptAchDetail")
    public TableDataInfo queryDeptAchDetail(DeptArchDTO deptArchDTO) throws ParseException {
        List<DeptArchDTO> list = busitaskService.queryDeptAchDetail(deptArchDTO);
        return getDataTable(list);
    }

    /**
     * 查询任务填报情况

     @PreAuthorize("@ss.hasPermi('sqeybusiness:busitask:list')")*/
    @PostMapping("/queryDeptTaskDetail")
    public TableDataInfo queryDeptTaskDetail(MonthStaticsDTO monthStaticsDTO) throws ParseException {
        List<MonthStaticsDTO> list = busitaskService.queryDeptTaskDetail(monthStaticsDTO);
        return getDataTable(list);
    }

    /**
     * 查询任务填报情况

     @PreAuthorize("@ss.hasPermi('sqeybusiness:busitask:list')")*/
    @PostMapping("/queryPsnlTaskDetail")
    public TableDataInfo queryPsnlTaskDetail(MonthStaticsDTO monthStaticsDTO) throws ParseException {
        List<MonthStaticsDTO> list = busitaskService.queryPsnlTaskDetail(monthStaticsDTO);
        return getDataTable(list);
    }
}
